{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "457c1f8f",
   "metadata": {},
   "source": [
    "-------------------\n",
    "* 日期：2022-9-21 \\ week05\n",
    "* 课程：python\n",
    "* 记录人：Zouyimeng\n",
    "-------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55bfe725",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "\n",
    "> 1.数值（number)\n",
    ">> 1. 定义\n",
    ">> 2. 方法\n",
    "\n",
    "> 2.字符串（string）\n",
    ">> 1. 定义\n",
    ">> 2. 方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb0289ab",
   "metadata": {},
   "source": [
    "## 1.数值\n",
    "\n",
    "> 1. 对数值进行分类\n",
    ">> 1. 整数(int)\n",
    ">> 2. 浮点型(float)\n",
    ">> 3. 复数(complex)\n",
    "\n",
    "> 2. 数值的运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2c00940f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "199"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "99+100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d4db9762",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整型\n",
    "a = 99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "486f23c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b = 99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "926fae9f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c = a + b\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "315f34a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数(虚数)\n",
    "d =2 + 3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80176af6",
   "metadata": {},
   "source": [
    "## 字符串(str)\n",
    "> 1. 定义\n",
    "> 2. 方法\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e0fb8482",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "29fc630a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8 8\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a = 8\n",
    "b = '8'\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "18ea1387",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (431899839.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [14]\u001b[1;36m\u001b[0m\n\u001b[1;33m    'don't'\u001b[0m\n\u001b[1;37m         ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 关于单引号和双引号\n",
    "'don't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "33c842d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"don't\""
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方法1\n",
    "\"don't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9f4d94ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"don't\""
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方法2 \\ 后面的内容是“符号”，转义， \\自动消失\n",
    "'don\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "04703d52",
   "metadata": {},
   "outputs": [],
   "source": [
    "# *正则表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "5588556e",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (2189814667.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [25]\u001b[1;36m\u001b[0m\n\u001b[1;33m    \"hello\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "\"hello \n",
    "world\n",
    "!\n",
    "!\n",
    "!\n",
    "\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "044bbaf4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 注释：\n",
    "# 如上，换行失败\n",
    "# 原因：双引号不能保持原数据的换行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "09c69dda",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可包含如何文本\n",
    "# 作用： \n",
    "# 1.保持原数据的结构，包含符号，换行等。\n",
    "# 2.可用来做代码注释\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c62fa821",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hello \\nworld\\n!\\n!\\n!\\n'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#三个引号保持原数据的换行\n",
    "\"\"\"hello \n",
    "world\n",
    "!\n",
    "!\n",
    "!\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c6e4fac0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n"
     ]
    }
   ],
   "source": [
    "# 用三个引号对代码进行注释\n",
    "# 例如：\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "南方学院学校要闻 = \"https://www.nfu.edu.cn/xxyw/index\"\n",
    "\n",
    "页面后缀 = \".htm\"\n",
    "page = 5\n",
    "\n",
    "\"\"\"\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻 + str(i) + 页面后缀) # 字符串拼接\n",
    "    random_num = random.randint(1,10) #随机秒数\n",
    "    print(\"该次停留\",random_num,'秒')\n",
    "    time.sleep(random_num)\n",
    "\"\"\"\n",
    "print(\"hello\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0051c12c",
   "metadata": {},
   "source": [
    "##  2.1字符串的运算法则\n",
    "> 1. 字符串的拼接\n",
    "> 2. <font color = \"red\">字符串有序性</font>\n",
    "> 3. enumerate: 枚举\n",
    "> 4. in 可以查询成员对象是否存在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "09b9a72a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'helloworld'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串的拼接\n",
    "\"hello\" + \"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "0a96e454",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，Alex\n",
      "你好，Marry\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "text = \"你好，\"\n",
    "for i in [\"Alex\",\"Marry\"]:\n",
    "    result = text + i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e050a30d",
   "metadata": {},
   "source": [
    "* 取值\n",
    "> 1. 取单个值\n",
    "> 2. 切片，取多个连续的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "4e033f46",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的有序性\n",
    "地址 = \"广州市从化区温泉镇882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "5d9907b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "f819ec48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "9b23b4f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "9bd509a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "174ff498",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "c5e989c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 广州 这个文本\n",
      "存在 广州 这个文本\n"
     ]
    }
   ],
   "source": [
    "# 实践：检查广州是否在 地址 里面？\n",
    "# 检查i 是否是广， 然后判断i [index+1]下一个索引值的内容是否是州？\n",
    "\n",
    "# 方法：enumerate枚举\n",
    "for index,value in enumerate(地址):\n",
    "    if value == \"广\":\n",
    "        if 地址[index+1] == \"州\":\n",
    "            print(\"存在 广州 这个文本\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "06fc6d1f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 方法： in 可以查询成员变量\n",
    "print(\"广州\" in 地址)\n",
    "print(\"Alex\" in 地址)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88d520a3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
